import { Body, Inject, Post, Get, Query } from '@midwayjs/core';
import { CoolController, BaseController,TagTypes,
  CoolTag } from '@cool-midway/core';
import { OrderOrderEntity } from '../../entity/order';
import { OrderPayService } from '../../service/orderPay';
import { UserInfoEntity } from '../../../user/entity/info';

/**
 * 订单信息
 */
@CoolController({
  prefix: "/apiwwwd/member",
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OrderOrderEntity,
  service: OrderPayService,
  pageQueryOp: {
    fieldEq: ['a.orderNum', 'a.userId'],
    keyWordLikeFields: ['a.consignee', 'a.phoneNumber'],
    fieldLike: [],
    // fieldEq: [
    //   { column: 'a.status', requestParam: 'status' },
    //   { column: 'a.payType', requestParam: 'payType' },
    // ],
    where: ctx => {
      const { createTime } = ctx.request.body;
      if (createTime && createTime.length === 2) {
        return [
          [
            'a.createTime BETWEEN :start AND :end',
            { start: createTime[0], end: createTime[1] },
          ],
        ];
      }
    },
    select: ['a.*', 'b.nickName'],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.userId = b.id',
        type: 'leftJoin',
      },
    ],
  },
})
export class AppOrderOrderController extends BaseController {
  @Inject()
  orderPayService: OrderPayService;

  @Inject()
  ctx;

}
